-- UIIntelligencePC
-- Created by cheny3 Oct/13/2016
-- 智能电脑

require "game/ui/form/equips/UIEquipTooltip"
require "game/ui/form/equips/UIEquips"

-- 材料图标缩放比例
local ITEM_ICON_SCALE = 0.6;
local BASE_SKILL_COST = ({1,7550,3});
local EXTRA_SKILL_COST = ({1,7551,1});

UIIntelligencePC = class("UIIntelligencePC", function()
    return cc.Layer:create();
end);

function UIIntelligencePC.create(gridData)
    return UIIntelligencePC.new(gridData);
end

-- 构造函数
function UIIntelligencePC:ctor(gridData)
    self:setName("UIIntelligencePC");

    -- 复用座钟界面
    local node = cc.CSLoader:createNode("layout/dungeon/special/DeskClock.csb");
    self:addChild(node);
    self.node = node;

    self:setLocalZOrder(UIMgr.TOP_MENU_ZORDER + 1);

    self.gridData  = gridData;

    -- 注册事件处理回调函数
    self:registerEventCallback();

    -- 注册点击事件
    self:registerTouchEvent();

    -- 主界面
    self.type = "main";

    -- 重绘
    self:redraw();

    -- 适配
    self:resize();
end

-- 适配
function UIIntelligencePC:resize()
    local node = self.node;

    -- bg居中显示并充满整个屏幕
    AlignM.fitToScreen(node, "bg");

    -- CT居中并缩放至合适大小
    AlignM.alignToCenter(node, "CT");

    -- BT置于底部并缩放至合适大小
    AlignM.alignToBottomCenter(node, "BT");
end

-- 注册事件处理回调函数
function UIIntelligencePC:registerEventCallback()
    -- 关注工坊放入装备的事件
    EventMgr.register("UIIntelligencePC", event.BLACKSMITH_INPUT_EQUIP, function(args)
        local classId = args.classId;
        if not classId then
            return;
        end

        self.classId = classId;

        -- 重绘信息
        self:redrawHolyItems();
    end);

    -- 关注圣器属性升级的事件
    EventMgr.register("UIIntelligencePC", event.HOLY_ITEMS_IMPROVE, function(args)
        local classId = args.classId;
        local level   = args.level;
        local upgradeType = args.upgradeType;
        local isSucc  =  args.isSucc;

        if self.classId ~= classId then
            return;
        end

        local effectNode = findChildByName(self.node, "CT/target_node/effect_node");
        effectNode:removeAllChildren();
        effectNode:setLocalZOrder(1);

        if upgradeType == "base"  then
            -- 基础属性提升
            local name = ItemM.query(classId, "name");
            local msg = string.format(getLocStr("holy_items_base_prop_improved"), name, level);
            alert(msg);
            playEffect(effectNode, 1262, 0, -45, nil);
        else
            -- 特殊属性提升
            local name = ItemM.query(classId, "name");
            local msg = string.format(getLocStr("machine_special_prop_improved"), name, level);
            alert(msg);
            playEffect(effectNode, 1262, 0, -45, nil);
        end

        -- 刷新界面
        self:redrawHolyItems();
    end);

    self:registerScriptHandler(function(eventType)
        if eventType == "exit" then
            cclog("UIIntelligencePC 界面析构清理");

            -- 移除所有事件关注
            EventMgr.removeAll("UIIntelligencePC");

            if UIDungeonMgr:getCurLevel() then
                UIDungeonMgr:getCurLevel():showMenu();
            end

        elseif eventType == "enter" then
            if UIDungeonMgr:getCurLevel() then
                UIDungeonMgr:getCurLevel():hideMenu();
            end
        end
    end);
end

-- 注册点击事件
function UIIntelligencePC:registerTouchEvent()
    -- 注册返回按钮点击事件
    local node = self.node;
    local btnBack = findChildByName(node, "BT/btn_back");
    local function onBackClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            AudioM.playFx("button_return");
            -- 关闭当前界面
            UIMgr.getCurrentScene():removeFormByName("UIIntelligencePC");
        end
    end
    AddBackEventHandler(self, btnBack, onBackClick);
    TextStyleM.setTextStyle(btnBack, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    btnBack:setTitleText(getLocStr("btn_text_back"));

    -- 第1个按钮效果
    local btnNode = findChildByName(node, "CT/btn_node");
    local btn1 = btnNode:getChildByName("btn_hour");
    local function onFirstClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            AudioM.playFx("button_select");
            self:onFirstBtnClick();
        end
    end
    AddTouchEventListener(btn1, onFirstClick);
    TextStyleM.setTextStyle(btn1, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    btn1:setTitleText(getLocStr("btn_text_pc1"));

    -- 第2个按钮效果
    local btn2 = btnNode:getChildByName("btn_minute");
    local function onSecondClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            AudioM.playFx("button_select");
            self:onSecondBtnClick();
        end
    end
    AddTouchEventListener(btn2, onSecondClick);
    TextStyleM.setTextStyle(btn2, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    btn2:setTitleText(getLocStr("btn_text_pc2"));

    -- 第3个按钮效果
    local btn3 = btnNode:getChildByName("btn_open");
    local function onThirdClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            AudioM.playFx("button_select");
            self:onThirdBtnClick();
        end
    end
    AddTouchEventListener(btn3, onThirdClick);
    TextStyleM.setTextStyle(btn3, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    btn3:setTitleText(getLocStr("btn_text_pc3"));

    -- 注册格子点击事件
    local frameImg = findChildByName(self.node, "CT/target_node/frame");
    local function onFrameClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            -- 打开包裹界面
            local uiEquip = UIEquips.create(EQUIP_OPEN_TYPE_HOLY_ITEMS, {["holy_type"] = "machine"});
            UIMgr.getCurrentScene():addForm(uiEquip);
        end
    end
    frameImg:addTouchEventListener(onFrameClick);
end

-- 显隐绘制节点
function UIIntelligencePC:showNodes()
    local descLabel  = findChildByName(self.node, "CT/desc");
    local iconImg    = findChildByName(self.node, "CT/icon");
    local timeLabel  = findChildByName(self.node, "CT/time_label");
    local targetNode = findChildByName(self.node, "CT/target_node");
    local itemNode   = findChildByName(self.node, "CT/item_node");
    local item2Node  = findChildByName(self.node, "CT/item2_node");
    local btn1       = findChildByName(self.node, "CT/btn_node/btn_hour");
    local btn2       = findChildByName(self.node, "CT/btn_node/btn_minute");
    local btn3       = findChildByName(self.node, "CT/btn_node/btn_open");
    local icon1      = findChildByName(btn1, "icon");
    local icon2      = findChildByName(btn2, "icon");

    -- 升级部分
    targetNode:setVisible(false);
    itemNode:setVisible(false);
    item2Node:setVisible(false);

    -- 描述部分
    iconImg:setVisible(true);
    descLabel:setVisible(true);
    timeLabel:setVisible(false);

    -- 按钮部分
    btn1:setVisible(true);
    btn2:setVisible(true);
    btn3:setVisible(true);
    btn1:setTouchEnabled(true);
    btn1:setBright(true);
    btn2:setTouchEnabled(true);
    btn2:setBright(true);
    icon1:setVisible(false);
    icon2:setVisible(false);

    if self.type == "main" or self.type == "news" then
        -- 主界面/新闻主界面

    elseif self.type == "police_info" or self.type == "social_news" then
        -- 新闻详细页
        btn1:setVisible(false);
        btn2:setVisible(false);
    elseif self.type == "upgrade" then
        iconImg:setVisible(false);

        -- 升级界面
        targetNode:setVisible(true);
        itemNode:setVisible(true);
        item2Node:setVisible(true);
        icon1:setVisible(true);
        icon2:setVisible(true);
    end
end

-- 升级界面
function UIIntelligencePC:redrawUpgrade()
    local kerning, kerning2 = 0, 0;
    if getLang() ~= "zh" and getLang() ~= "tw" then
        kerning, kerning2 = -3, -1;
    end

    -- 描述
    local descLabel  = findChildByName(self.node, "CT/desc");
    TextStyleM.setTextStyle(descLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_DARK_BROWN, false, kerning2);
    descLabel = applyString(descLabel, getLocStr("pc_upgrade_equip_desc"));

    -- 隐藏圣器图标
    local equipImg = findChildByName(self.node, "CT/target_node/icon");
    self.equipImg = equipImg;
    checkAddBubbleStatus(self.equipImg);
    local frame = findChildByName(self.node, "CT/target_node/frame");

    -- 初始化消耗
    self:initUpgradeBaseCost();
    self:initUpgradeSpecialCost();

    local btn3 = findChildByName(self.node, "CT/btn_node/btn_open");
    btn3:setTitleText(getLocStr("btn_text_pc4"));
end

-- 新闻详细界面
function UIIntelligencePC:redrawNews()
    local descLabel  = findChildByName(self.node, "CT/desc");
    local iconImg    = findChildByName(self.node, "CT/icon");
    local btn3       = findChildByName(self.node, "CT/btn_node/btn_open");

    local kerning, kerning2 = 0, 0;
    if getLang() ~= "zh" and getLang() ~= "tw" then
        kerning, kerning2 = -3, -1;
    end

    -- 图片
    local iconPath = getLevelItemIconPath("terminal");
    iconImg:loadTexture(iconPath);
    iconImg:setScale(1.3);
    iconImg:setOpacity(64);

    -- 描述
    local id = self.gridData.news_ids[self.type];
    local dialog = IntelligencePCM.queryNews(id, "dialog");
    TextStyleM.setTextStyle(descLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_DARK_BROWN, false, kerning2);
    descLabel = applyString(descLabel, dialog);

    -- 按钮
    btn3:setTitleText(getLocStr("btn_text_pc4"));

    if not IntelligencePCM.hasUserRead(id) then
        -- 阅读
        DungeonActionM.go("read_pc_news", self.gridData:getPos(), id);
    end
end

-- 新闻主界面
function UIIntelligencePC:redrawNewsMain()
    local descLabel  = findChildByName(self.node, "CT/desc");
    local iconImg    = findChildByName(self.node, "CT/icon");
    local btn1       = findChildByName(self.node, "CT/btn_node/btn_hour");
    local btn2       = findChildByName(self.node, "CT/btn_node/btn_minute");
    local btn3       = findChildByName(self.node, "CT/btn_node/btn_open");

    local kerning, kerning2 = 0, 0;
    if getLang() ~= "zh" and getLang() ~= "tw" then
        kerning, kerning2 = -3, -1;
    end

    -- 图片
    local iconPath = getLevelItemIconPath("terminal");
    iconImg:loadTexture(iconPath);
    iconImg:setScale(1.3);
    iconImg:setOpacity(255);

    -- 描述
    TextStyleM.setTextStyle(descLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_DARK_BROWN, false, kerning2);
    descLabel = applyString(descLabel, getLocStr("pc_see_more_desc"));

    -- 按钮
    btn1:setTitleText(getLocStr("btn_text_pc5"));
    btn2:setTitleText(getLocStr("btn_text_pc6"));
    btn3:setTitleText(getLocStr("btn_text_pc4"));
end

-- 主界面
function UIIntelligencePC:redrawMain()
    local descLabel  = findChildByName(self.node, "CT/desc");
    local iconImg    = findChildByName(self.node, "CT/icon");
    local btn1       = findChildByName(self.node, "CT/btn_node/btn_hour");
    local btn2       = findChildByName(self.node, "CT/btn_node/btn_minute");
    local btn3       = findChildByName(self.node, "CT/btn_node/btn_open");

    local kerning, kerning2 = 0, 0;
    if getLang() ~= "zh" and getLang() ~= "tw" then
        kerning, kerning2 = -3, -1;
    end

    -- 图片
    local iconPath = getLevelItemIconPath("terminal");
    iconImg:loadTexture(iconPath);
    iconImg:setScale(1.3);
    iconImg:setOpacity(255);

    -- 描述
    TextStyleM.setTextStyle(descLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_DARK_BROWN, false, kerning2);
    descLabel = applyString(descLabel, getLocStr("intelligence_pc_desc"));

    -- 按钮
    btn1:setTitleText(getLocStr("btn_text_pc1"));
    btn2:setTitleText(getLocStr("btn_text_pc2"));
    btn3:setTitleText(getLocStr("btn_text_pc3"));

    -- 领完就置灰
    local pos = self.gridData:getPos();
    local grid = DungeonM.getGridByPos(pos);
    if grid.bonus_id then
        btn1:setTouchEnabled(true);
        btn1:setBright(true);
    else
        btn1:setTouchEnabled(false);
        btn1:setBright(false);
    end
end

-- 重绘
function UIIntelligencePC:redraw()
    local titleLabel = findChildByName(self.node, "CT/title_node/title");
    titleLabel:setString(getLocStr("intelligence_pc_title"));
    TextStyleM.setArtWordTitleStyle(titleLabel);

    -- 清空特效节点
    local effectNode = findChildByName(self.node, "CT/target_node/effect_node");
    effectNode:removeAllChildren();
    effectNode:setLocalZOrder(1);

    -- 显隐节点处理
    self:showNodes();

    if self.type == "main" then
        -- 主界面
        self:redrawMain();
    elseif self.type == "news" then
        -- 新闻主界面
        self:redrawNewsMain();
    elseif self.type == "upgrade" then
        -- 升级界面
        self:redrawUpgrade();
    elseif self.type == "police_info"
        or self.type == "social_news" then
        -- 新闻详细界面
        self:redrawNews();
    end
end

-- 初始化基础消耗显示
function UIIntelligencePC:initUpgradeBaseCost()
    local itemNode = findChildByName(self.node, "CT/item_node");
    local priceLabel = findChildByName(itemNode, "amount");
    local upgradeCost = BASE_SKILL_COST;
    local itemId  = upgradeCost[2];
    local curAmount = ItemM.getAmount(ME.user, itemId);
    TextStyleM.setTextStyle(priceLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE);

    -- 显示当前数量
    priceLabel:setString(curAmount .. "/" .. getLocStr("default_value_text2"));

    local iconImg = findChildByName(itemNode, "icon");
    local icon = ItemM.query(itemId, "icon");
    iconImg:loadTexture(getItemIconPath(icon));
    iconImg:setScale(ITEM_ICON_SCALE);

    -- 提升按钮置灰
    local btnBase = findChildByName(self.node, "CT/btn_node/btn_hour");
    self.btnBase = btnBase;
    TextStyleM.setTextStyle(btnBase, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    setButtonEnabled(btnBase, false);
    self.btnBase:setTitleText(getLocStr("improve_base_prop"));
    local iconImg = findChildByName(self.btnBase, "icon");
    iconImg:loadTexture(getItemIconPath(icon));
    iconImg:setScale(ITEM_ICON_SCALE);
end

-- 初始化特殊消耗显示
function UIIntelligencePC:initUpgradeSpecialCost()
    local itemNode = findChildByName(self.node, "CT/item2_node");
    local priceLabel = findChildByName(itemNode, "amount");
    local upgradeCost = EXTRA_SKILL_COST;
    local itemId  = upgradeCost[2];
    local curAmount = ItemM.getAmount(ME.user, itemId);
    TextStyleM.setTextStyle(priceLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE);
    priceLabel:setString(curAmount .. "/" .. getLocStr("default_value_text2"));

    local iconImg = findChildByName(itemNode, "icon");
    local icon = ItemM.query(itemId, "icon");
    iconImg:loadTexture(getItemIconPath(icon));
    iconImg:setScale(ITEM_ICON_SCALE);

    -- 提升按钮置灰
    local btnExtra = findChildByName(self.node, "CT/btn_node/btn_minute");
    self.btnExtra = btnExtra;
    TextStyleM.setTextStyle(btnExtra, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    setButtonEnabled(btnExtra, false);
    self.btnExtra:setTitleText(getLocStr("improve_special_prop2"));
    local iconImg = findChildByName(self.btnBase, "icon");
    iconImg = findChildByName(self.btnExtra, "icon");
    iconImg:loadTexture(getItemIconPath(icon));
    iconImg:setScale(ITEM_ICON_SCALE);
end

-- 显示提升基础属性消耗
function UIIntelligencePC:redrawUpgradeBaseCost()
    local itemNode  = findChildByName(self.node, "CT/item_node");
    local upgradeCost = self.baseUpgradeCost;
    local itemId  = upgradeCost[2];
    local amount  = upgradeCost[3];
    local curAmount = ItemM.getAmount(ME.user, itemId);

    local priceLabel = findChildByName(itemNode, "amount");

    -- 消耗不足时，红色显示
    local isEnough = ItemM.getAmount(ME.user, itemId) >= amount;
    if not isEnough then
        TextStyleM.setTextStyle(priceLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_DARK_RED);
    else
        TextStyleM.setTextStyle(priceLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE);
    end

    local isMaxLevel = HolyItemsM.isBaseLevelMax(self.classId);
    if isMaxLevel then
        -- 等级已达上限
        priceLabel:setString(curAmount .. "/" .. getLocStr("default_value_text2"));
    else
        priceLabel:setString(curAmount .. "/" .. amount);
    end

    local iconImg = findChildByName(itemNode, "icon");
    local icon = ItemM.query(itemId, "icon");
    iconImg:loadTexture(getItemIconPath(icon));
    iconImg:setScale(ITEM_ICON_SCALE);

    -- 获取当前基础属性的等级
    local curLevel = HolyItemsM.getBaseLevel(self.classId);

    if isMaxLevel then
        -- 基础属性等级已达上限
        setButtonEnabled(self.btnBase, false);
        self.btnBase:setTitleText(getLocStr("max_level_yet"));
    elseif not isEnough then
        -- 消耗不足
        setButtonEnabled(self.btnBase, false);
        self.btnBase:setTitleText(getLocStr("improve_base_prop") .. "+" .. curLevel + 1);
    else
        -- 升级按钮亮起来
        setButtonEnabled(self.btnBase, true);
        self.btnBase:setTitleText(getLocStr("improve_base_prop") .. "+" ..curLevel + 1);
    end
end

-- 显示提升特殊属性消耗
function UIIntelligencePC:redrawUpgradeExtraCost()
    local itemNode = findChildByName(self.node, "CT/item2_node");

    local upgradeCost = self.extraUpgradeCost;
    local itemId  = upgradeCost[2];
    local amount  = upgradeCost[3];
    local curAmount = ItemM.getAmount(ME.user, itemId);

    -- 消耗不足时，红色显示
    local priceLabel = findChildByName(itemNode, "amount");
    local isEnough = ItemM.getAmount(ME.user, itemId) >= amount;
    if not isEnough then
        TextStyleM.setTextStyle(priceLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_DARK_RED);
    else
        TextStyleM.setTextStyle(priceLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE);
    end

    local isMaxLevel = HolyItemsM.isExtraLevelMax(self.classId);
    if isMaxLevel then
        priceLabel:setString(curAmount .. "/" .. getLocStr("default_value_text2"));
    else
        priceLabel:setString(curAmount .. "/" .. amount);
    end

    local iconImg = findChildByName(itemNode, "icon");
    local icon = ItemM.query(itemId, "icon");
    iconImg:loadTexture(getItemIconPath(icon));
    iconImg:setScale(ITEM_ICON_SCALE);

    -- 获取当前特殊属性的等级
    local curLevel = HolyItemsM.getExtraLevel(self.classId);

    if isMaxLevel then
        -- 特殊属性等级已达上限
        setButtonEnabled(self.btnExtra, false);
        self.btnExtra:setTitleText(getLocStr("max_level_yet"));
    elseif not isEnough then
        -- 消耗不足
        setButtonEnabled(self.btnExtra, false);
        self.btnExtra:setTitleText(getLocStr("improve_special_prop2") .. "+" ..  curLevel + 1);
    else
        -- 升级按钮亮起来
        setButtonEnabled(self.btnExtra, true);
        self.btnExtra:setTitleText(getLocStr("improve_special_prop2")  .. "+" .. curLevel + 1);
    end
end

-- 重绘圣器信息
function UIIntelligencePC:redrawHolyItems()
    -- 计算升级附加属性的消耗
    local baseUpgradeCost = BASE_SKILL_COST;
    self.baseUpgradeCost = baseUpgradeCost;

    -- 计算升级基础属性的消耗
    local extraUpgradeCost = EXTRA_SKILL_COST;
    self.extraUpgradeCost = extraUpgradeCost;

    -- 显示圣器图标
    local frame = findChildByName(self.node, "CT/target_node/frame");
    frame:removeAllChildren();

    local icon = ItemM.query(self.classId, "icon");
    self.equipImg:setVisible(true);
    self.equipImg:loadTexture(getItemIconPath(icon));

    -- 显示消耗
    self:redrawUpgradeBaseCost();
    self:redrawUpgradeExtraCost();

    -- 显示按钮上的小图标
    local itemId = self.baseUpgradeCost[2];
    local icon = ItemM.query(itemId, "icon");
    local iconImg = findChildByName(self.btnBase, "icon");
    iconImg:loadTexture(getItemIconPath(icon));
    iconImg:setScale(ITEM_ICON_SCALE);

    itemId = self.extraUpgradeCost[2];
    icon = ItemM.query(itemId, "icon");
    iconImg = findChildByName(self.btnExtra, "icon");
    iconImg:loadTexture(getItemIconPath(icon));
    iconImg:setScale(ITEM_ICON_SCALE);
end

-- 尝试提升基础属性
function UIIntelligencePC:tryUpgradeBaselevel(classId)
    -- 执行提升
    DungeonActionM.go("holy_items_base_improve", 0, classId);
end

-- 尝试提升特殊属性
function UIIntelligencePC:tryUpgradeExtralevel(classId)
    -- 获取当前特殊属性的等级
    local curLevel = HolyItemsM.getExtraLevel(classId);

    -- 判断基础属性等级是否达标
    local requireBaseLevel = FormulaM.invoke("CALC_HOLY_ITEMS_BASE_LEVEL_REQUIRE", classId, curLevel);
    local curBaseLevel = HolyItemsM.getBaseLevel(classId);
    if curBaseLevel < requireBaseLevel then
        local msg = string.format(getLocStr("fail_to_upgrade_specail_prop"), requireBaseLevel);
        alert(msg);
        return;
    end

    -- 执行提升
    DungeonActionM.go("holy_items_extra_improve", 0, classId);
end

-- 尝试获得奖励
function UIIntelligencePC:takePcBonus()
    -- 提升
    local pos = self.gridData:getPos();
    DungeonActionM.go("take_pc_bonus", pos);
    -- 关闭界面
    UIMgr.getCurrentScene():removeFormByName("UIIntelligencePC");
end

-- 按下第1个按钮
function UIIntelligencePC:onFirstBtnClick()
    if self.type == "main" then
        self:takePcBonus();
    elseif self.type == "upgrade" then
        if not self.classId then
            return;
        end

        -- 尝试提升基本属性
        self:tryUpgradeBaselevel(self.classId);
    elseif self.type == "news" then
        -- 警署档案
        self.type = "police_info";
        self:redraw();
    end
end

-- 按下第2个按钮
function UIIntelligencePC:onSecondBtnClick()
    if self.type == "main" then
        self.type = "upgrade";
        self:redraw();
    elseif self.type == "upgrade" then
        if not self.classId then
            return;
        end

        -- 尝试提升特殊属性
        self:tryUpgradeExtralevel(self.classId);
    elseif self.type == "news" then
        -- 社会新闻
        self.type = "social_news";
        self:redraw();
    end
end

-- 按下第3个按钮
function UIIntelligencePC:onThirdBtnClick()
    if self.type == "main" then
        self.type = "news";
        self:redraw();
    elseif self.type == "upgrade" or self.type == "news" then
        self.type = "main";
        self:redraw();
    elseif self.type == "social_news" or self.type == "police_info" then
        self.type = "news";
        self:redraw();
    end
end